package com.dly.hope.dao;

import com.dly.hope.modle.QUserAccount;
import com.dly.hope.modle.QWebSocketMessage;
import com.dly.hope.modle.WebSocketMessage;
import com.dly.hope.vo.SessionVo;
import com.querydsl.core.types.Projections;
import io.swagger.models.auth.In;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class WebSocketMessageDao extends BaseDao{

    private QWebSocketMessage basePath(){
        return QWebSocketMessage.webSocketMessage;
    }

    private  static final QUserAccount userAccount = QUserAccount.userAccount;

    public Integer getNotRead(String sendId, String acceptId){
        return queryFactory
                .selectFrom(basePath())
                .where(basePath().sendId.eq(sendId).and(basePath().acceptId.eq(acceptId)).and(basePath().isRead.eq(false)))
                .fetch()
                .size();
    }

    public List<WebSocketMessage> getMessage(String sendId, String acceptId){
        return queryFactory
                .selectFrom(basePath())
                .where(basePath().sendId.in(sendId, acceptId).and(basePath().acceptId.in(sendId,acceptId)).and(basePath().dataStatus.eq(1)))
                .orderBy(basePath().createDate.asc())
                .fetch();
    }

    public List<WebSocketMessage> getGroupMessage(String acceptId){
        return queryFactory
                .selectFrom(basePath())
                .where(basePath().acceptId.eq(acceptId).and(basePath().dataStatus.eq(1)))
                .orderBy(basePath().createDate.asc())
                .fetch();
    }
}
